<!--
 * @Description: 授权中间跳转
 * @Author BPF
 * @create 2021/8/24 14:23
 -->
<template>
  <global-ant-loading class="loading__wrap"></global-ant-loading>
</template>

<script setup>
import { getCurrentInstance, onMounted } from 'vue'
import { call } from '/src/store/plugins/vuex-helper'
import { message } from 'ant-design-vue'

const { proxy } = getCurrentInstance()
const getAccessToken_ = call('user/getAccessToken')

onMounted(async () => {
  const { query } = proxy.$route
  try {
    if (query.code) {
      await getAccessToken_(query.code)
      if (query?.redirect_url) {
        window.location.href = query?.redirect_url
      } else {
        proxy.$router.push('/')
      }
      setTimeout(() => {
        message.success('登录成功~')
      })
    }
  } catch (e) {
    await call('user/logOut')
    call('user/loginToThirdParty')
  }
})
</script>

<style scoped lang="less">
.loading__wrap {
  width: 84px;
  height: 84px;
  position: absolute;
  top: 200px;
  left: 0;
  right: 0;
  margin: auto;
  z-index: 100;
}
</style>
